﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Lop_HocVien_Lop : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadGrv();
            LoadDDL();
            LoadMess();
        }
    }

    private void LoadMess()
    {
        if (Session["Mess"] != null && Session["Type"].ToString().Equals("Success"))
        {
            String mess = "<div class='alert alert-success alert-dismissable'>";
            mess += "<i class='fa fa-check'></i>";
            mess += "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>";
            mess += Session["Mess"].ToString() + "</div>";
            Session.Remove("Mess");
            Session.Remove("Type");
            ltrMess.Text = mess;
        }
        if (Session["Mess"] != null && Session["Type"].ToString().Equals("Error"))
        {
            String mess = "<div class='alert alert-danger alert-dismissable'>";
            mess += "<i class='fa fa-ban'></i>";
            mess += "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>";
            mess += Session["Mess"].ToString() + "</div>";
            Session.Remove("Mess");
            Session.Remove("Type");
            ltrMess.Text = mess;
        }
    }
    private void LoadGrv()
    {
        List<LopINFO> dsloaicauhoi = LopDAL.listAll();
        ddllophoc.DataSource = dsloaicauhoi;
        ddllophoc.DataTextField = "TenLop";
        ddllophoc.DataValueField = "MaLop";
        ddllophoc.DataBind();
        ddllophoc.Items.Insert(0, new ListItem("Chọn lớp học", "0"));
    }
    private void LoadDDL()
    {
        int ma = int.Parse(ddllophoc.SelectedValue.ToString());
        DataTable ds = LopDAL.timkiem(ma);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void ddllophoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadDDL();
    }
    protected void refresh_Click(object sender, EventArgs e)
    {
        LoadDDL();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView obj = (DataRowView)e.Row.DataItem;
            string trangthai = "<span class='label label-success'>Được phép thi</span>";
            if (obj["TinhTrang"].ToString().Equals("0"))
                trangthai = "<span class='label label-danger'>Không được phép thi</span>";
            Literal lbltrangthai = (Literal)e.Row.FindControl("ltrTinhTrang");
            lbltrangthai.Text = trangthai;
        }
    }
}